home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / SCREEN.SWG / 0057_Screen Writes.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  2KB  |  76 lines

  1. {
  2. > how do you write a string directly to the screen (the window is not always
  3. > 80 columns)?
  4.  
  5. A "well behaved" direct screen write routine queries the number of columns on
  6. the screen as returned in the AH register after calling INT 10h, AH=0Fh.
  7. Multiply it by 2 times the number of the Y coordinate (zero-based) and add 2
  8. times the number of the X coordinate (zero-based too).  This yields the
  9. offset into the video segment.  The segment value is 0B000h if AL as returned
  10. by aforementioned call is 7, 0B800h otherwise.  Use the SegB000 and SegB800
  11. selectors for DPMI apps.
  12.  
  13. Example follows for DOS real mode.  Note: doesn't perform "snow checking".
  14. }
  15.  
  16. Var
  17.   ScreenSeg   : Word;
  18.   ScreenWidth : Word;
  19.   Columns     : Word;
  20.  
  21. Procedure WriteXY(x, y : Integer; attr : Byte; s : String); Assembler;
  22.  
  23. ASM
  24.   CLD
  25.   PUSH   DS
  26.   MOV    ES, [ScreenSeg]         { get start address }
  27.   MOV    AX, [y]
  28.   DEC    AX
  29.   IMUL   [ScreenWidth]
  30.   MOV    DX, [x]
  31.   DEC    DX
  32.   SHL    DX, 1
  33.   ADD    AX, DX
  34.   XCHG   AX, DI
  35.  
  36.   MOV    AH, [attr]
  37.  
  38.   LDS    SI, [s]                 { load string to display }
  39.   LODSB
  40.   SUB    CH, CH
  41.   MOV    CL, AL
  42.   JCXZ   @2
  43.  
  44.  @1:
  45.   LODSB                          { loop - move to screen }
  46.   STOSW
  47.   LOOP   @1
  48.  @2:
  49.   POP    DS
  50. end;
  51.  
  52. { unit's initialisation code... }
  53.  
  54. Begin  { Screen }
  55.   ASM
  56.     MOV    AH, 0Fh
  57.     INT    10h
  58.     PUSH   AX
  59.     MOV    AL, AH
  60.     SUB    AH, AH
  61.     MOV    [ScreenWidth], AX
  62.     MOV    [Columns], AX
  63.     SHL    [ScreenWidth], 1
  64.     POP    AX
  65.     CMP    AL, 7
  66.     JNE    @2
  67.  
  68.     MOV    Byte Ptr [ScreenSeg+1], 0B0h
  69.     JMP    @4
  70.  
  71.     { deleted for brevity ... }
  72.    @2:
  73.    @4:
  74.   end;
  75. end.
  76.